Ext.define('DragonApp.view.monster.filter.LevelGroup', {
    extend: 'Ext.form.RadioGroup',

    xtype: 'monster_level_group',

    fieldLabel: '条件细分',

    defaultType: 'radiofield',
    defaults: {
        width: 130
    },

    items: [
        { boxLabel: '不限', name: 'level', inputValue: '0', checked: true },
        { boxLabel: '1~2星', name: 'level', inputValue: '1' },
        { boxLabel: '3~4星', name: 'level', inputValue: '2' },
        { boxLabel: '5~6星', name: 'level', inputValue: '3' },
        { boxLabel: '7~8星', name: 'level', inputValue: '4' },
        { boxLabel: '9~10星', name: 'level', inputValue: '5' }
    ],
    listeners: {

        change: {

            fn: function() {

                var value = this.getValue();
                var store = Ext.data.StoreManager.lookup('jsonPmonsterStore');

                for (key in value) {
                    //清理条件过滤
                    store.clearFilter();

                    //字段筛选
                    if ('0' != value[key]) {

                        switch (value[key]) {
                            case '1':
                                store.filterBy(function(record) {
                                    return record.get('level') == '1' || record.get('level') == '2';
                                });
                                break;
                            case '2':
                                store.filterBy(function(record) {
                                    return record.get('level') == '3' || record.get('level') == '4';
                                });
                                break;
                            case '3':
                                store.filterBy(function(record) {
                                    return record.get('level') == '5' || record.get('level') == '6';
                                });
                                break;
                            case '4':
                                store.filterBy(function(record) {
                                    return record.get('level') == '7' || record.get('level') == '8';
                                });
                                break;
                            case '5':
                                store.filterBy(function(record) {
                                    return record.get('level') == '9' || record.get('level') == '10';
                                });
                                break;
                        }
                    }
                }

            }
        }
    }
});